#include "cppunit/extensions/HelperMacros.h"
#include "../source/string_ext.h"

class Testcase_string_ext : public CPPUNIT_NS::TestFixture
{
	CPPUNIT_TEST_SUITE( Testcase_string_ext );
	CPPUNIT_TEST( test01 );
	CPPUNIT_TEST( test02 );
	CPPUNIT_TEST( test03 );
	CPPUNIT_TEST( test04 );
	CPPUNIT_TEST( test05 );
	CPPUNIT_TEST( test06 );
	CPPUNIT_TEST_SUITE_END();

public:
	Testcase_string_ext();
	virtual ~Testcase_string_ext();
	void setUp(void);
	void tearDown(void);

	void test01(void);
	void test02(void);
	void test03(void);
	void test04(void);
	void test05(void);
	void test06(void);
};

CPPUNIT_TEST_SUITE_REGISTRATION( Testcase_string_ext );
 
Testcase_string_ext::Testcase_string_ext() { }
Testcase_string_ext::~Testcase_string_ext() { }
void Testcase_string_ext::setUp(void) { }
void Testcase_string_ext::tearDown(void) { }

void Testcase_string_ext::test01(void) { 
	StringExt s;
	size_t size = s.split(",").size();
	CPPUNIT_ASSERT_EQUAL(size, size_t(0));
}

void Testcase_string_ext::test02(void) { 
	string st = "hello";
	StringExt s = st;

	vector<StringExt> result = s.split(",");
	CPPUNIT_ASSERT_EQUAL(size_t(1), result.size());
	CPPUNIT_ASSERT_EQUAL(StringExt("hello"), result.at(0));
}

void Testcase_string_ext::test03(void) { 
	StringExt s = "hello world";

	vector<StringExt> result;

	vector<StringExt> excepted;
	excepted.push_back("hello");
	excepted.push_back("world");

	result = s.split();
	CPPUNIT_ASSERT_EQUAL(excepted.size(), result.size());
	for(size_t i = 0; i < result.size(); i++)
		CPPUNIT_ASSERT_EQUAL(excepted.at(i), result.at(i));
}

void Testcase_string_ext::test04(void) { 
	StringExt s = "abcabcabc";

	vector<StringExt> result;

	vector<StringExt> excepted;
	excepted.push_back("a");
	excepted.push_back("a");
	excepted.push_back("a");
	excepted.push_back("");

	result = s.split("bc");
	CPPUNIT_ASSERT_EQUAL(excepted.size(), result.size());
	for(size_t i = 0; i < result.size(); i++)
		CPPUNIT_ASSERT_EQUAL(excepted.at(i), result.at(i));
}

void Testcase_string_ext::test05(void) { 
	StringExt s = "aBc#123,";
	StringExt excepted = "ABC#123,";

	StringExt result = s.upper();

	CPPUNIT_ASSERT_EQUAL(excepted, result);
}

void Testcase_string_ext::test06(void) { 
	StringExt s = "aBC#123,";
	StringExt excepted = "abc#123,";

	StringExt result = s.lower();

	CPPUNIT_ASSERT_EQUAL(excepted, result);
}
